// 导入request.js请求工具
import request from '@/utils/request'
// 提供调用注册接口的函数
export const userRegisterService = (registerData) => {
    // 借助于urlSearchParams完成传递
    const params = new URLSearchParams()
    for(let key in registerData){
        params.append(key, registerData[key]);
    }
    //console.log(params);
    return request.post('/user/register', params);
}
//提供调用登录接口的函数
export const userLoginService = (loginData) => {
    const params = new URLSearchParams()
    for(let key in loginData){
        params.append(key, loginData[key]);
    }
    console.log(params);
    return request.post('/user/login', params);
}
//用户列表查询
//import axios from 'axios';

export const userListService = {
    get(params) {
        //console.log("获取用户列表请求参数：", params); // 打印参数，确认是否正确
        return request.get('/user/list', { params });
    },
    update(data) {  // 修改用户权限接口
        console.log("修改用户权限参数：", data); // 打印参数，确认是否正确
        return request.put('/user/updatePermission', data, {
            headers: { 'Content-Type': 'multipart/form-data' }  // 必须设置 Content-Type
        });
    },
    delete(id) {  
        console.log("删除用户 ID：", id); 
        return request.delete('/user/delete', { 
            params: { id: id }  
        });
    }
}
//获取个人用户信息
export const getUserInfoService = () => {
    return request.get('/user/userInfo')
}
//修改个人信息
export const userInfoUpdateService = (userInfoData)=>{
    return request.put('/user/update',userInfoData)
 }
 
 //修改头像
 export const userAvatarUpdateService = (avatarUrl)=>{
     const params = new URLSearchParams();
     params.append('avatarUrl',avatarUrl)
     console.log('api_avatar', avatarUrl)
     return request.patch('/user/updateAvatar',params)
 }
 // 修改密码
export const userPasswordUpdateService = (data) => {
    return request.patch('/user/updatePassword', data)
}